/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.

* File utils.h
* Description: handle file operations
*/
#pragma once


#include <unistd.h>
#include <string>

#include "acl/acl.h"
#include "acl/ops/acl_dvpp.h"
#include "opencv2/opencv.hpp"

using namespace std;

enum MemoryType {
    MEMORY_NORMAL = 0,
    MEMORY_HOST,
    MEMORY_DEVICE,
    MEMORY_DVPP,    
    MEMORY_INVALID_TYPE
};

enum CopyDirection {
    TO_DEVICE = 0,
    TO_HOST,
    INVALID_COPY_DIRECT
};

enum CameraId {
    CAMERA_ID_0 = 0,
    CAMERA_ID_1,
    CAMERA_ID_INVALID,
};

struct ImageData {
    acldvppPixelFormat format;
    std::string name;
    uint32_t id;
    uint32_t width = 0;
    uint32_t height = 0;
    uint32_t alignWidth = 0;
    uint32_t alignHeight = 0;
    uint32_t size = 0;
    std::shared_ptr<uint8_t> data = nullptr;
};

struct FrameData {
    bool isFinished = false;
    uint32_t frameId = 0;
    uint32_t size = 0;
    void* data = nullptr;
};

struct Resolution {
    uint32_t width = 0;
    uint32_t height = 0;
};

struct Rect {
    float ltX = 0;
    float ltY = 0;
    float rbX = 0;
    float rbY = 0;
};

// struct BBox {
//     Rect rect;
//     uint32_t score = 0;
//     string text;
// };

#define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO]  " fmt "\n", ##args)
#define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN]  " fmt "\n", ##args)
#define ERROR_LOG(fmt, args...) fprintf(stdout, "[ERROR] " fmt "\n", ##args)

typedef struct BBox {
    BBox(cv::Rect rect=cv::Rect(0,0,0,0), float score=0, int cls_id=-1, int trk_id=-1, uint32_t index=0) {
        this->rect = rect;
        this->score = score;
        this->cls_id = cls_id;
        this->trk_id = trk_id;
        this->index = index;
    }
    cv::Rect2f rect;
    float score;
    int cls_id;
    int trk_id;
    uint32_t index;
} BBox;

struct Vector {
	float x;
	float y;
};

struct Box {
	Vector top_left;
	Vector bottom_right;
};

struct Target_Box
{
	Vector pos;
	Vector size;
};

typedef enum Result {
    SUCCESS = 0,
    FAILED = 1
} Result;



struct AtlasMessage {
    int dest;
    int msgId;
    std::shared_ptr<void> data = nullptr;
};

struct DataInfo {
    void* data;
    uint32_t size;
};

struct InferenceOutput {
    shared_ptr<void> data = nullptr;
    uint32_t size;
};